import os, string, sys
import openpyxl

OSInfo_workbook=openpyxl.load_workbook('Apoo_SystemDesign_eMMC_rawinfo.xlsx')

os.system("rm -f light.txt")

filename = open('light.txt', 'a')
for end_sheet_map_table in OSInfo_workbook['light'].iter_rows(min_row=2,max_row=967,min_col=1,max_col=7):
	filename.write(str(end_sheet_map_table[0].value) + ' ')
	filename.write(str(end_sheet_map_table[1].value) + ' ')
	filename.write(str(end_sheet_map_table[2].value) + ' ')
	filename.write(str(end_sheet_map_table[3].value) + ' ')
	filename.write(str(end_sheet_map_table[4].value) + ' ')
	filename.write(str(end_sheet_map_table[5].value) + ' ')
	filename.write(str(end_sheet_map_table[6].value) + '\n')
filename.close()

filename = open('light.txt', 'a')
for end_sheet_map_table in OSInfo_workbook['light'].iter_rows(min_row=968,max_row=1159,min_col=1,max_col=7):
	filename.write(str(end_sheet_map_table[0].value) + ' ')
	filename.write(str(end_sheet_map_table[1].value) + ' ')
	filename.write(str(end_sheet_map_table[2].value) + ' ')
	filename.write(str(end_sheet_map_table[3].value) + ' ')
	if '0x' in str(end_sheet_map_table[4].value) or 'need_crc_calculation' in str(end_sheet_map_table[4].value) or 'none' in str(end_sheet_map_table[4].value) or 'None' in str(end_sheet_map_table[4].value):
		filename.write(str(end_sheet_map_table[4].value) + ' ')
	else:
		value=hex(int(end_sheet_map_table[4].value))
		value=value[2:].zfill(4)
		filename.write(value + ' ')
	filename.write(str(end_sheet_map_table[5].value) + ' ')
	filename.write(str(end_sheet_map_table[6].value) + '\n')
filename.close()

filename = open('light.txt', 'a')
filename.write('reserved:' + str(OSInfo_workbook['light']['F1161'].value) + '\n')
filename.close()

os.system("/bin/bash genLightConfig.sh light.txt")
